package com.edu.exam.entity.assessment.technical;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 相似度配置实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：similarity_config
 *
 * 根据B-02-06试题查重子模块设计文档实现
 * 管理相似度算法配置，支持多种算法参数调优和阈值设置。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "similarity_config")
@Comment("相似度配置表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SimilarityConfig {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 相似度配置唯一标识符
     */
    @NotBlank(message = "相似度配置ID不能为空")
    @Size(max = 50, message = "相似度配置ID长度不能超过50个字符")
    @Column(name = "config_id", nullable = false, length = 50, unique = true)
    private String configId;

    /**
     * 配置名称
     */
    @NotBlank(message = "配置名称不能为空")
    @Size(max = 100, message = "配置名称长度不能超过100个字符")
    @Column(name = "config_name", nullable = false, length = 100)
    private String configName;

    /**
     * 配置描述
     */
    @Size(max = 500, message = "配置描述长度不能超过500个字符")
    @Column(name = "config_description", length = 500)
    private String configDescription;

    /**
     * 算法类型（TEXT-文本相似度，SEMANTIC-语义相似度，STRUCTURE-结构相似度，HYBRID-混合算法）
     */
    @NotBlank(message = "算法类型不能为空")
    @Size(max = 20, message = "算法类型长度不能超过20个字符")
    @Column(name = "algorithm_type", nullable = false, length = 20)
    private String algorithmType;

    /**
     * 配置类型（GLOBAL-全局配置，LIBRARY-题库配置，SUBJECT-学科配置，CUSTOM-自定义配置）
     */
    @NotBlank(message = "配置类型不能为空")
    @Size(max = 20, message = "配置类型长度不能超过20个字符")
    @Column(name = "config_type", nullable = false, length = 20)
    private String configType;

    /**
     * 适用范围（JSON格式，定义配置的适用范围）
     */
    @Column(name = "applicable_scope", columnDefinition = "TEXT")
    private String applicableScope;

    /**
     * 相似度阈值
     */
    @Column(name = "similarity_threshold", precision = 5, scale = 4)
    private BigDecimal similarityThreshold;

    /**
     * 高相似度阈值
     */
    @Column(name = "high_similarity_threshold", precision = 5, scale = 4)
    private BigDecimal highSimilarityThreshold;

    /**
     * 中相似度阈值
     */
    @Column(name = "medium_similarity_threshold", precision = 5, scale = 4)
    private BigDecimal mediumSimilarityThreshold;

    /**
     * 低相似度阈值
     */
    @Column(name = "low_similarity_threshold", precision = 5, scale = 4)
    private BigDecimal lowSimilarityThreshold;

    /**
     * 权重配置（JSON格式，各种算法或特征的权重）
     */
    @Column(name = "weight_config", columnDefinition = "TEXT")
    private String weightConfig;

    /**
     * 算法参数（JSON格式，算法的具体参数）
     */
    @Column(name = "algorithm_params", columnDefinition = "TEXT")
    private String algorithmParams;

    /**
     * 文本预处理配置（JSON格式，文本预处理参数）
     */
    @Column(name = "text_preprocessing_config", columnDefinition = "TEXT")
    private String textPreprocessingConfig;

    /**
     * 特征提取配置（JSON格式，特征提取参数）
     */
    @Column(name = "feature_extraction_config", columnDefinition = "TEXT")
    private String featureExtractionConfig;

    /**
     * 匹配策略配置（JSON格式，匹配策略参数）
     */
    @Column(name = "matching_strategy_config", columnDefinition = "TEXT")
    private String matchingStrategyConfig;

    /**
     * 性能优化配置（JSON格式，性能优化相关参数）
     */
    @Column(name = "performance_config", columnDefinition = "TEXT")
    private String performanceConfig;

    /**
     * 缓存配置（JSON格式，缓存相关参数）
     */
    @Column(name = "cache_config", columnDefinition = "TEXT")
    private String cacheConfig;

    /**
     * 并行处理配置（JSON格式，并行处理参数）
     */
    @Column(name = "parallel_config", columnDefinition = "TEXT")
    private String parallelConfig;

    /**
     * 质量控制配置（JSON格式，质量控制参数）
     */
    @Column(name = "quality_control_config", columnDefinition = "TEXT")
    private String qualityControlConfig;

    /**
     * 输出配置（JSON格式，输出格式和内容配置）
     */
    @Column(name = "output_config", columnDefinition = "TEXT")
    private String outputConfig;

    /**
     * 版本号
     */
    @Size(max = 20, message = "版本号长度不能超过20个字符")
    @Column(name = "version", length = 20)
    private String version;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 是否为默认配置
     */
    @NotNull(message = "默认配置状态不能为空")
    @Column(name = "is_default", nullable = false)
    private Boolean isDefault;

    /**
     * 生效时间
     */
    @Column(name = "effective_time")
    private LocalDateTime effectiveTime;

    /**
     * 失效时间
     */
    @Column(name = "expiry_time")
    private LocalDateTime expiryTime;

    /**
     * 配置排序
     */
    @Column(name = "sort_order")
    private Integer sortOrder;

    /**
     * 优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 最小文本长度
     */
    @Column(name = "min_text_length")
    private Integer minTextLength;

    /**
     * 最大文本长度
     */
    @Column(name = "max_text_length")
    private Integer maxTextLength;

    /**
     * 支持的语言列表（JSON数组格式）
     */
    @Column(name = "supported_languages", columnDefinition = "TEXT")
    private String supportedLanguages;

    /**
     * 支持的题型列表（JSON数组格式）
     */
    @Column(name = "supported_question_types", columnDefinition = "TEXT")
    private String supportedQuestionTypes;

    /**
     * 排除条件（JSON格式，不参与查重的条件）
     */
    @Column(name = "exclusion_conditions", columnDefinition = "TEXT")
    private String exclusionConditions;

    /**
     * 包含条件（JSON格式，必须参与查重的条件）
     */
    @Column(name = "inclusion_conditions", columnDefinition = "TEXT")
    private String inclusionConditions;

    /**
     * 统计信息（JSON格式，配置使用统计）
     */
    @Column(name = "statistics", columnDefinition = "TEXT")
    private String statistics;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Long usageCount;

    /**
     * 最后使用时间
     */
    @Column(name = "last_used_time")
    private LocalDateTime lastUsedTime;

    /**
     * 配置状态（DRAFT-草稿，ACTIVE-激活，INACTIVE-停用，DEPRECATED-废弃）
     */
    @NotBlank(message = "配置状态不能为空")
    @Size(max = 20, message = "配置状态长度不能超过20个字符")
    @Column(name = "config_status", nullable = false, length = 20)
    private String configStatus;

    /**
     * 审核状态（PENDING-待审核，APPROVED-已审核，REJECTED-已拒绝）
     */
    @Size(max = 20, message = "审核状态长度不能超过20个字符")
    @Column(name = "approval_status", length = 20)
    private String approvalStatus;

    /**
     * 审核人员ID
     */
    @Size(max = 50, message = "审核人员ID长度不能超过50个字符")
    @Column(name = "approved_by", length = 50)
    private String approvedBy;

    /**
     * 审核人员姓名
     */
    @Size(max = 100, message = "审核人员姓名长度不能超过100个字符")
    @Column(name = "approved_by_name", length = 100)
    private String approvedByName;

    /**
     * 审核时间
     */
    @Column(name = "approval_time")
    private LocalDateTime approvalTime;

    /**
     * 审核意见
     */
    @Size(max = 1000, message = "审核意见长度不能超过1000个字符")
    @Column(name = "approval_comment", columnDefinition = "TEXT")
    private String approvalComment;

    /**
     * 创建者ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}